#!/usr/bin/env python3
"""
Simple test script for AgentMemory monitoring system
"""

import asyncio
import sys
import os

# Add the parent directory to Python path
try:
    parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    sys.path.append(parent_dir)
    from base_code import *
    from base_code.common import *
except ImportError:
    print("Error: Cannot find 'base_code' module. Please ensure pocketflow code is in correct path.")

from react_agent import ReActAgent
from local_tools import GLOBAL_TOOL_SYSTEM

async def simple_test():
    """Simple test of the monitoring system"""
    print("Testing AgentMemory Monitoring System")
    print("=" * 50)

    # Create ReActAgent with monitoring enabled
    agent = ReActAgent(
        tools_system=GLOBAL_TOOL_SYSTEM,
        local_llm="qwen3:4b",
        remote_llm="qwen3-plus",
        enable_monitoring=True,
        monitor_port=8000
    )

    print("ReActAgent created with monitoring enabled")
    print("Monitoring service should be available at: http://localhost:8000")
    print("\n" + "=" * 50)

    # Test a simple task
    task = "What is 2 + 2?"
    print(f"Task: {task}")
    print("-" * 30)

    try:
        # Process the task
        result = await agent.process_command_async(task)
        print(f"Result: {result}")

        # Show agent memory state
        agent.show_memo(verbose=False)

    except Exception as e:
        print(f"Error processing task: {e}")
        import traceback
        traceback.print_exc()

    print("\nTesting completed!")
    print("Check the monitoring interface at: http://localhost:8000")
    print("\nTo stop the monitoring service, press Ctrl+C...")

    # Keep the script running so monitoring stays active
    try:
        while True:
            await asyncio.sleep(1)
    except KeyboardInterrupt:
        print("\nShutting down...")
        agent.stop_monitoring()

if __name__ == "__main__":
    asyncio.run(simple_test())